<template>
  <div>
    <van-field v-model="form.name" placeholder="请输入用户名"></van-field>
    <van-field v-model="form.mobile" placeholder="请输入手机号" :rules="[{'required':true,'message':'必须输入手机号'}]"></van-field>
    <van-button @click="send">发送验证码</van-button>
    <van-field v-model="form.codes" placeholder="请输入验证码"></van-field>
    <van-field v-model="form.password" placeholder="请输入密码"></van-field>
    <van-field v-model="form.password2" placeholder="请再次输入密码"></van-field>
    <van-button @click="regi">注册</van-button>
  </div>
</template>

<script>
export default {
  name: "regi_user",
  data() {
    return {
      form: {}
    }
  },
  methods: {
    send() {
      let re = /^1[3-9]\d{9}$/
      if (!re.test(this.form.mobile)) {
        alert('手机号格式不正确')
        return
      }
      this.$axios.get('/user/send?mobile=' + this.form.mobile)
        .then(res => {
          if (res.data.code == 200) {
            alert('发送成功')
            alert(res.data.codes)
          }
        })
    },
    regi() {
      if (this.form.password != this.form.password2) {
        alert('两次密码不一致，请重新输入')
        return
      }
      this.$axios.post('/user/regi',this.form)
        .then(res => {
          if (res.data.code == 200) {
            alert('注册成功')
            this.form = {}
          }
          else {
          alert(res.data.mes)}

        })


    }
  }
}
</script>

<style scoped>

</style>
